package com.xpgk.mvc.bloseWeight;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jfinal.log.Log;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.xpgk.annotation.Table;
import com.xpgk.mvc.base.BaseModel;
import com.xpgk.mvc.codeSet.Code;
import com.xpgk.mvc.measurement.Temporary;

/**
 * 
 * 减重目标汇总
 * 
 */

@SuppressWarnings("unused")
@Table(tableName = DelWeiTargetSum.table_name)
public class DelWeiTargetSum extends BaseModel<DelWeiTargetSum> {

	private static final long serialVersionUID = -81076304749709337L;

	private static final Log log = Log.getLog(DelWeiTargetSum.class);

	public static final DelWeiTargetSum dao = new DelWeiTargetSum().dao();

	
	/**
	 * 表名称
	 */
	public static final String table_name = "sb_customer_dtarget";

	/**
	 * 字段描述：主键 字段类型：character varying 长度：32
	 */
	public static final String column_ids = "ids";

	/**
	 * 字段描述：顾客ids 字段类型：character varying 长度：32
	 */
	public static final String column_customerIds = "customerIds";
	
	/**
	 * 字段描述：目标模式 字段类型：character varying 长度：255
	 */
	public static final String column_codeIds = "codeIds";
	/**
	 * 字段描述：目标名称 字段类型：character varying 长度：255
	 */
	public static final String column_targetName = "targetName";
	/**
	 * 字段描述：起始时间 字段类型：date
	 */
	public static final String column_startTime = "startTime";

	/**
	 * 字段描述：结束时间 字段类型：date
	 */
	public static final String column_endTime = "endTime";
	
	/**
	 * 字段描述：起始体重
	 */
	public static final String column_startWei = "startWei";
	/**
	 * 字段描述：目标体重
	 */
	public static final String column_targetWei = "targetWei";
	/**
	 * 字段描述：应减体重
	 */
	public static final String column_delWei = "delWei";
	

	/**
	 * 字段描述：状态） 默认：0 字段类型：character 长度：1
	 */
	public static final String column_dataStatus = "dataStatus";
	/**
	 * 字段描述：该条数据添加人员is  字段类型：character varying 长度：32
	 */
	public static final String column_createId = "createId";
	/**
	 * 字段描述：该条数据添加时间  字段类型：datetime 长度：0
	 */
	public static final String column_createDate = "createDate";
	/**
	 * 字段描述：该条数据更新人员id  字段类型：character varying 长度：100
	 */
	public static final String column_updateId = "upateId";
	/**
	 * 字段描述：该条数据更新时间  字段类型：datetime 长度：0
	 */
	public static final String column_updateDate = "updateDate";
	
	
	
	/**
	 * sqlId :sb.delWeiTarget.column 描述：查询减重目标，自定义字段
	 */
	public static final String sqlId_column = "sb.delWeiTargetSum.column";
	
	/**
	 * sqlId :sb.delWeiTarget.selByCusAndDate 描述：查询减重目标排期下数据
	 */
	public static final String sqlId_selByCusAndDate = "sb.delWeiTargetSum.selByCusAndDate";
	
	/**
	 * sqlId :分页查询select
	 */
	public static final String sqlId_splitPageSelect = "sb.delWeiTargetSum.splitPageSelect";
	
	/**
	 * sqlId :分页查询from
	 */
	public static final String sqlId_splitPageFrom = "sb.delWeiTargetSum.splitPageFrom";
	
	
	
	/**
	 * 关联查询获取目标列表
	 * @return
	 */
	public List<DelWeiTarget> getTargets(){
		return DelWeiTarget.dao.findTargetBySum(this.getPKValue());
	}
	
	/**
	 * 获取指定顾客的最后一条排期
	 * 结束时间加一天时间
	 * @param customerIds
	 * @return
	 */
	public Record findCustomerLastOneTarget(String customerIds){
		String sql = "select date_add(endTime, INTERVAL 1 day) endTime from sb_customer_dtarget where customerIds = ? ORDER BY endTime DESC LIMIT 1";
		return Db.findFirst(sql, customerIds);
	}
	
	/**
	 * 查询某一个顾客所有总目标
	 * @param customerIds
	 * @return
	 */
	public List<DelWeiTargetSum> getTargetsByCustomer(String customerIds){
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("column", column_customerIds);
		String sql = getSqlByBeetl(sqlId_column, param);
		return find(sql, customerIds);
	}

}
